Conditions | 10 |
Total Lines | 46 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Complex classes like include-module-plugin-in-id.js ➔ includeModulePluginInId often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | function includeModulePluginInId(module, plugin, el_id, success, error) { |
||
2 | var elmnt = document.getElementById(el_id); |
||
3 | |||
4 | var domain = '/origini-app/visitor/'; |
||
5 | var filename = '/'; |
||
|
|||
6 | var file = domain + '' + module + '/plugin/' + plugin + '.html'; // + filename; |
||
7 | var xhttp; |
||
8 | |||
9 | if (typeof success !== 'function') { |
||
10 | success = function () { |
||
11 | console.log('success', "included"); |
||
12 | } |
||
13 | } |
||
14 | |||
15 | if (typeof error !== 'function') { |
||
16 | error = function () { |
||
17 | console.log('error', "Page not found."); |
||
18 | } |
||
19 | } |
||
20 | console.log('file', file); |
||
21 | |||
22 | if (file) { |
||
23 | /* Make an HTTP request using the attribute value as the file name: */ |
||
24 | xhttp = new XMLHttpRequest(); |
||
25 | xhttp.onreadystatechange = function () { |
||
26 | if (this.readyState == 4) { |
||
27 | if (this.status == 200) { |
||
28 | |||
29 | elmnt.innerHTML = this.responseText; |
||
30 | |||
31 | success(); |
||
32 | } |
||
33 | if (this.status == 404) { |
||
34 | error(); |
||
35 | |||
36 | } |
||
37 | /* Remove the attribute, and call this function once more: */ |
||
38 | // includeHtml(file, success, error); |
||
39 | } |
||
40 | } |
||
41 | xhttp.open("GET", file, true); |
||
42 | xhttp.send(); |
||
43 | /* Exit the function: */ |
||
44 | return; |
||
45 | } |
||
46 | } |
||
47 |